$(function() {

    layui.use(['layer'], function() {
        var layer = layui.layer;

        /**
         * 标签页切换
         */
        $("#tab-demo .layui-tab-title li").on("click", function() {
            $("#tab-demo .layui-tab-title li").removeClass("layui-btn layui-this");
            $(this).addClass("layui-btn layui-this");
            var tabContent = $("#tab-demo .layui-tab-content > div");
            tabContent.removeClass("layui-show");
            tabContent.eq($(this).index()).addClass("layui-show");
        });

        /**
         * Ajax + form表单上传(单个)
         */
        $("#image-upload-btn").on("click", function(){
            $.ajax({
                processData: false,
                contentType: false,
                cache: false,
                type: "post",
                url: "../oss/uploadfile",
                data: new FormData($("#image-box")[0]),
                async: false,
                dataType: "json",
                success: function (result) {
                    layer.msg(result.message);
                },
                error: function (result) {
                    layer.msg(result.code + " - " + result.message);
                }
            });
        });

    });
});